const jwt = require('jsonwebtoken');

const secretKey = 'your_secret_key'; // Replace with your actual secret key

const tokenService = {
    generateToken: (user) => {
        const payload = { id: user.id, username: user.username };
        const options = { expiresIn: '1h' }; // Token expires in 1 hour
        return jwt.sign(payload, secretKey, options);
    },

    verifyToken: (token) => {
        try {
            return jwt.verify(token, secretKey);
        } catch (error) {
            return null; // Token is invalid
        }
    }
};

module.exports = tokenService;